<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程设计</title>
    <link rel="stylesheet" href="../../component/snaker/snaker.css" type="text/css" media="all"/>
</head>
<body class="pear-container">
<div id="toolbox">
    <div id="toolbox_handle">工具集</div>
    <div class="node" id="save"><img src="../../component/snaker/images/save.gif"/>&nbsp;&nbsp;保存</div>
    <div>
        <hr/>
    </div>
    <div class="node selectable" id="pointer">
        <img src="../../component/snaker/images/select16.gif"/>&nbsp;&nbsp;Select
    </div>
    <div class="node selectable" id="path">
        <img src="../../component/snaker/images/16/flow_sequence.png"/>&nbsp;&nbsp;transition
    </div>
    <div>
        <hr/>
    </div>
    <div class="node state" id="start" type="start"><img
            src="../../component/snaker/images/16/start_event_empty.png"/>&nbsp;&nbsp;start
    </div>
    <div class="node state" id="end" type="end"><img
            src="../../component/snaker/images/16/end_event_terminate.png"/>&nbsp;&nbsp;end
    </div>
    <div class="node state" id="task" type="task"><img
            src="../../component/snaker/images/16/task_empty.png"/>&nbsp;&nbsp;task
    </div>
    <div class="node state" id="task" type="custom"><img
            src="../../component/snaker/images/16/task_empty.png"/>&nbsp;&nbsp;custom
    </div>
    <div class="node state" id="task" type="subprocess"><img
            src="../../component/snaker/images/16/task_empty.png"/>&nbsp;&nbsp;subprocess
    </div>
    <div class="node state" id="fork" type="decision"><img
            src="../../component/snaker/images/16/gateway_exclusive.png"/>&nbsp;&nbsp;decision
    </div>
    <div class="node state" id="fork" type="fork"><img
            src="../../component/snaker/images/16/gateway_parallel.png"/>&nbsp;&nbsp;fork
    </div>
    <div class="node state" id="join" type="join"><img
            src="../../component/snaker/images/16/gateway_parallel.png"/>&nbsp;&nbsp;join
    </div>
</div>

<div id="properties">
    <div id="properties_handle">属性</div>
    <table class="properties_all" cellpadding="0" cellspacing="0">
    </table>
    <div>&nbsp;</div>
</div>

<div id="snakerflow"></div>


<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>


<script src="../../component/snaker/raphael-min.js" type="text/javascript"></script>
<script src="../../component/snaker/jquery-ui-1.8.4.custom/js/jquery.min.js" type="text/javascript"></script>
<script src="../../component/snaker/jquery-ui-1.8.4.custom/js/jquery-ui.min.js" type="text/javascript"></script>
<script src="../../component/snaker/dialog.js" type="text/javascript"></script>
<script src="../../component/snaker/snaker.designer.js" type="text/javascript"></script>
<script src="../../component/snaker/snaker.model.js" charset="utf-8" type="text/javascript"></script>
<script src="../../component/snaker/snaker.editors.js" type="text/javascript"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'common', 'easyAdmin'], function () {
        let easyAdmin = layui.easyAdmin;
        id = getQueryString("processId");
        easyAdmin.httpGet("/flow/process/modelJson?processId=" + id, function (data) {
            var model = "";
            if (data) {
                model = eval("(" + data + ")");
            }
            var userJson = {};
            easyAdmin.httpGet("/sys/user/getAll", function (result) {
                if (result.success) {
                    userJson = result.data;
                }
            }, true, false);
            $('#snakerflow').snakerflow({
                basePath: "../../component/snaker/",
                ctxPath: "/",
                restore: model,
                userJson: userJson,
                formPath: "forms/",
                tools: {
                    save: {
                        onclick: function (data) {
                            // alert(data);
                            saveModel(data);
                        }
                    }
                }
            });
        });


        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r !== null)
                return unescape(r[2]);
            return "";
        }


        window.saveModel = function (data) {
            easyAdmin.http({
                type: 'POST',
                url: "/flow/process/deployXml",
                data: "model=" + data + "&id=" + id,
                async: false,
                globle: false,
                error: function () {
                    alert('数据处理错误！');
                    return false;
                },
                success: function (data) {
                    if (data == true) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("user-table");
                    } else {
                        layer.msg("没有修改权限哦！flow.update", {
                            icon: 2,
                            time: 1000,
                            area: ['300px', '65px']
                        });
                    }
                }
            });

        }
    })
</script>
</body>
</html>
